package com.zhong.gang.app.ui.waidiao.detail;

import androidx.annotation.NonNull;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.zhong.gang.app.R;
import com.zhong.gang.app.api.Api;
import com.zhong.gang.app.api.HttpUtils;
import com.zhong.gang.app.databinding.ActivityWaiDiaoDetailBinding;
import com.zhong.gang.app.utils.waidiaoimg.WaidiaoImgAdapter;
import com.zhong.gang.applib.base.act.ActBase;
import com.zhong.gang.applib.http.BaseDataBean;
import com.zhong.gang.applib.utils.NumberUtils;

public class WaiDiaoDetailAct extends ActBase<ActivityWaiDiaoDetailBinding> {
    private static final String ID = "ID";
    public static final void openAct(Context context,int id){
        Intent intent = new Intent(context,WaiDiaoDetailAct.class);
        intent.putExtra(ID,id);
        context.startActivity(intent);
    }

    @Override
    public boolean showLoading() {
        return true;
    }

    @Override
    public int LayoutRes() {
        return R.layout.activity_wai_diao_detail;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "订单详情";
    }

    @Override
    public void initView() {
        getData();
    }

    @Override
    public void getData() {
        super.getData();
        HttpUtils.get(Api.externalDetail,this)
                .addParams("orderId",getIntent().getIntExtra(ID,0)+"")
                .build().execute(new ActCallBack<BaseDataBean<WaiDiaoDetailBean>>(){
            @Override
            public void onResponse(BaseDataBean<WaiDiaoDetailBean> data) throws Exception {
                super.onResponse(data);
                if (data.getResult() == null)
                    return;
                WaiDiaoDetailBean bean = data.getResult();
                bind.carType.setText(bean.getCarType() == 0?"公司派车":"货主自有车辆 ");
                bind.carNum.setText(bean.getCarNum());
                bind.sn.setText(bean.getSn());
                bind.payWay.setText(bean.getPayType()==0?"打款放车":"钢厂结算");
                if (bean.getSteelMill() != null) {
                    bind.endAddress.setText(bean.getSteelMill().getName());
                }
                bind.shipperView.showEdt(false);
                bind.shipperView.setData(data.getResult().getConsignor());

                bind.xcMWeight.setText(NumberUtils.getNumber(data.getResult().getStartLocalGrossWeight())+"吨");
                bind.xcPWeight.setText(NumberUtils.getNumber(data.getResult().getStartLocalTareWeight())+"吨");
                bind.xcKWeight.setText(NumberUtils.getNumber(data.getResult().getStartLocalSlagWeight())+"吨");
                bind.xcJWeight.setText(NumberUtils.getNumber(data.getResult().getStartLocalFinalWeight())+"吨");
                bind.xcKWeightLayout.setVisibility(bean.getPayType() == 0?View.VISIBLE:View.GONE);

                bind.xcZkMoney.setText(NumberUtils.getNumber(data.getResult().getFloatAmount() == 0?0:((data.getResult().getFloatType() == 1 ? 1 :-1)*data.getResult().getFloatAmount()))+"元");
                bind.xcZkMoneyLayout.setVisibility(bean.getPayType() == 0?View.VISIBLE:View.GONE);
                bind.finalMoney.setText(NumberUtils.getNumber(data.getResult().getStartLocalFinalAmount())+"元");

                bind.material.setData(data.getResult().getOrderMaterialTypeDetailList(),bean.getPayType()==0);
                bind.carImgView.addItem(new WaidiaoImgAdapter.WaiDiaoImgBean(data.getResult().getCarPhoto(),"车辆照片"));
                bind.carImgView.addItem(new WaidiaoImgAdapter.WaiDiaoImgBean(data.getResult().getMaterialTypePhoto(),"货物合照"));
                if (data.getResult().getOrderConfirmToFactory() == null || data.getResult().getOrderConfirmToFactory().getContract() == null) {
                    bind.bdLayout.setVisibility(View.GONE);
                    return;
                }
                WaiDiaoDetailBean.OrderConfirmToFactory orderBean = data.getResult().getOrderConfirmToFactory();
                bind.orderSn.setText(orderBean.getSn());
                bind.mWeight.setText(orderBean.getSteelMillGrossWeight()+"吨");
                bind.pWeight.setText(orderBean.getSteelMillTareWeight()+"吨");
                bind.jWeight.setText(orderBean.getSteelMillNetWeight()+"吨");
                bind.zjStatus.setText(orderBean.isQualityCheckResult()?"：是":"：否");
                bind.kouWeight.setText(orderBean.getSteelMillSlagWeight()+"吨");
                bind.jsWeight.setText(orderBean.getSteelMillFinalWeight()+"吨");
                bind.otherImgView.addItem(new WaidiaoImgAdapter.WaiDiaoImgBean(orderBean.getSteelMillQualityPhoto(),"质检单照片"));
                bind.otherImgView.addItem(new WaidiaoImgAdapter.WaiDiaoImgBean(orderBean.getSteelMillPoundPhoto(),"磅单照片"));
                bind.materialDetailView.setData(data.getResult().getOrderConfirmToFactory().getContract().getContractMaterialTypes());
                bind.bdLayout.setVisibility(View.VISIBLE);
            }
        });
    }
}
